package com.zhongwang.mms.module.buy.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.common.Page;
import com.zhongwang.mms.common.Table;
import com.zhongwang.mms.module.buy.model.ShoppingPlanModel;
import com.zhongwang.mms.module.buy.service.MaterialReturnService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description: 原材料回货确认
 *  * 查看 -> plan:matretconfirm:view
 *  * 回货确认 -> plan:materialretconfirm:confirm
 *
 * @Author: China.sgl
 * @Date: 2020/4/7 14:42
 */
@SuppressWarnings("ALL")
@Controller
@RequestMapping("/buy/materialReturn")
public class MaterialReturnController extends BaseController {

    @Autowired
    private MaterialReturnService service;

    /**
     * 原材料回货页面
     *
     * @return 路径
     */
    @GetMapping
    @RequiresPermissions({"plan:matretconfirm:view"})
    public String page() {
        return "buy/materialReturn/page";
    }

    /**
     * 外购件回货列表数据
     *
     * @param shoppingPlanModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions({"plan:matretconfirm:view"})
    public JsonResult list(ShoppingPlanModel shoppingPlanModel) {
        startPage();
        List<ShoppingPlanModel> list = service.findMaterialReturn(shoppingPlanModel);
        return jsonResult(list);
//        Page page = Page.getPage();
//        PageHelper.startPage(page.getPageNum(), page.getPageSize());
//        List<ShoppingPlanModel> list = service.findMaterialReturn(shoppingPlanModel);
//        Table model = new Table();
//        model.setRows(list);
//        model.setTotal(service.findMaterialReturnCount(shoppingPlanModel));
//        return success().setData(model);
    }

    /**
     * 查询所有入库记录
     *
     * @param shoppingPlanModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/store/list")
    @RequiresPermissions({"plan:matretconfirm:view"})
    public JsonResult storeList(ShoppingPlanModel shoppingPlanModel) {
        startPage();
        List<ShoppingPlanModel> list = service.findOrderDetail(shoppingPlanModel);
        return jsonResult(list);
    }

    /**
     * 确认回货
     *
     * @param rppId 提报计划主键
     * @param odaId 入库主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/submit")
    @RequiresPermissions({"plan:materialretconfirm:confirm"})
    public JsonResult submit(Integer rppId, Integer odaId) {
        return jsonResult(service.submitReturn(rppId, odaId));
    }

    /**
     * 批量确认回货
     *
     * @param rppId 提报计划主键数组
     * @param odaId 入库记录主键数组
     * @return json
     */
    @ResponseBody
    @PostMapping("/submit/all")
    @RequiresPermissions({"plan:materialretconfirm:confirm"})
    public JsonResult submit(Integer[] rppId, Integer[] odaId) {
        return jsonResult(service.submitReturn(rppId, odaId));
    }

    /**
     * 撤消回货确认
     *
     * @param id 主键
     * @return json
     */
    @ResponseBody
    @PostMapping("/cancel")
    @RequiresPermissions({"plan:materialretconfirm:confirm"})
    public JsonResult cancel(Integer id) {
        return jsonResult(service.cancelRetrun(id));
    }

}
